package com.y2.authprj.utils.login;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.gdglc.spring.biz.auth.FunctionauthorityBiz;
import com.y2.authprj.bean.auth.model.FunctionauthorityInfo;
import com.y2.authprj.exception.BizException;

public class LoginCheckUntil {
	
	private FunctionauthorityBiz biz; 
 	
	
	public LoginCheckUntil(){
		ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		this.biz = (FunctionauthorityBiz)context.getBean("FunctionauthorityBiz");
	}
	//根据资源名称查找存在的资源的Id
	public int findFunctionauthorityIdByName(String name){
			try {
				 List<FunctionauthorityInfo> findAll = biz.findAll();
				
				for(FunctionauthorityInfo f:findAll){
					if(f.getName().equals(name)){
						return f.getFunctionauthorityId();
					}
				}
			} catch (BizException e) {
				e.printStackTrace();
			}
			return -1;
		}
	
	//根据用户的ID查找对应的资源
	public List<Integer> functionauthorityIdByStaffId(int staffId){
		
		List<Integer> idList = biz.findFunctionauthorityIdByStaffId(staffId);
		if(idList!=null){
			return idList;
		}
		return null;
		
	}
		public static void main(String[] args) {
			LoginCheckUntil until=new LoginCheckUntil();
			
			System.out.println(until.findFunctionauthorityIdByName("查询资源"));
		}
}
